import 'package:flutter/material.dart';

// 淡入淡出动画

class PageOverAnimation extends StatefulWidget {
  const PageOverAnimation({super.key});

  @override
  State<PageOverAnimation> createState() => _PageOverAnimationState();
}

class _PageOverAnimationState extends State<PageOverAnimation> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      appBar: AppBar(
        title: const Text('Home page'),
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            Navigator.push(
              context,
              PageRouteBuilder(
                pageBuilder: (context, animation, secondAnimation) =>
                    const SecondPage(),
                transitionsBuilder:
                    (context, animation, secondAnimation, child) {
                  return FadeTransition(opacity: animation, child: child);
                },
              ),
            );
          },
          child: const Text('Go on second Page'),
        ),
      ),
    );
  }
}

class SecondPage extends StatelessWidget {
  const SecondPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        title: const Text('Second page'),
      ),
      body: const Center(
        child: Text('welcome to second page'),
      ),
    );
  }
}
